package com.wlyuan.index.domain.index.valueobj;

import com.wlyuan.index.domain.index.CombineIndex;
import com.wlyuan.index.domain.index.WaybillIndex;
import lombok.Data;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Optional;

;

/**
 * @author yuanjie
 */
@Deprecated
@Data
public class Quotation implements Serializable {
    public static final Integer ENDED = 1;

    @Field(type = FieldType.Long)
    private Long quotationId;
    @Field(type = FieldType.Keyword)
    private String quotationNo;
    @Field(type = FieldType.Integer)
    private Integer status;
    @Field(type = FieldType.Integer)
    private Integer source;

    public int getPriority() {
        return Optional.ofNullable(this.status)
                .map(QuotationStatus::valueOf)
                .map(QuotationStatus::getPriority)
                .orElse(0);
    }

    public static boolean canQuote(Integer status) {
        return QuotationStatus.canQuote(status);
    }

    // 已关闭运单/已过关账期 -> 报价: 已关闭
    public static boolean endQuote(Relation relation, WaybillIndex index) {
        return relation.endQuote()
                || WaybillStatus.endQuote(relation.getStatus())
                || index.endBill();
    }

    public static boolean endQuote(Relation relation, CombineIndex index) {
        return relation.endQuote()
                || CombineStatus.endQuote(relation.getStatus())
                || index.endBill();
    }
}